/**
 * @author:albert
 */

package com.bkbw.live.battle.business.skill;

import java.util.HashMap;
import com.bkbw.live.common.dataproto.EnumConfigPb.BuffAccumulate;
import com.bkbw.live.battle.business.GameObject;

public class BuffBase {
	protected String buffId;
	
	protected GameObject obj;
	
	protected int effectValue;
	protected float duration;
	protected float tick;
	protected float period;
	protected float tickPeriod;
	
	protected BuffAccumulate accumulate = BuffAccumulate.AccumulateDefault;
	
	protected int dynamicId;
	protected static int BuffDynamicId = 1;
	
	public BuffBase(String buffId, HashMap<String, Object> param)
	{
		this.buffId = buffId;
		this.effectValue = (int)param.get("effectValue");
		this.duration = (float)param.get("duration");
		this.tick = 0;
		this.period = (float)param.get("period");
		this.tickPeriod = 0;
		this.dynamicId = BuffDynamicId++;
	}

	// --------- getter & setter ---------
	public int getDynamicId() {
		return dynamicId;
	}

	public BuffAccumulate getAccumulate()
	{
		return accumulate;
	}
	
	public String getBuffId()
	{
		return buffId;
	}
	
	// ---------------------------------
	
	public void bind(GameObject obj)
	{
		this.obj = obj;
	}
	
	public void unbind()
	{
		this.obj = null;
	}
	
	public void update(float dt)
	{
		this.tick += dt;
		this.tickPeriod += dt;
		if (this.tick >= this.duration) {
			//this.obj.unbindBuff(this);
			return;
		}
		if (this.tickPeriod >= this.period) {
			onBuffEffect();
			this.tickPeriod = 0;
		}
	}
	
	public void onBuffEffect()
	{
		
	}
	
	public void AccumulateReset(HashMap<String, Object> param) 
	{
		this.effectValue = (int)param.get("effectValue");
		this.duration = (float)param.get("duration");
		this.tick = 0;
	}
	
	public void AccumulateTime(HashMap<String, Object> param) 
	{
		this.duration = (float)param.get("duration");
	}
	
	public void AccumulateEffect(HashMap<String, Object> param) 
	{
		this.effectValue += (int)param.get("effectValue");
		this.duration = (float)param.get("duration");
		this.tick = 0;
	}
}
